/*
 * $Author: isan.wong@gmail.com $
 * $Date: 2011-07-29 01:03:06 +0000 (Fri, 29 Jul 2011) $
 * $Rev: 13 $
 * $URL: http://capitalbio-smd.googlecode.com/svn/src/com/capitalbio/smd/gui/SMD.java $
 */

package com.capitalbio.smd.gui;

import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.capitalbio.smd.base.Util;

/**
 * SVD (Sequence Variation Detector 程序主入口类)
 * 
 * @author Wang Lei
 */
public class SMD {
	protected static Log log = LogFactory.getLog(SMD.class);
	
	public static void main(String argv[]) {
		final SplashWindow splashWindow = new SplashWindow();
		final MainFrame mainFrame = new MainFrame();

		try {
			UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
			//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
			SwingUtilities.updateComponentTreeUI(mainFrame);
		} catch (Exception e) {
			log.error(e);
		}

		mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		mainFrame.pack();
		
		Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension sz = new Dimension(mainFrame.getWidth(),
				mainFrame.getHeight());
		mainFrame.setLocation((scr.width - sz.width) / 2,
				(scr.height - sz.height) / 2);
		//mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);

		splashWindow.setVisible(true);
		try {
			Thread.sleep(2000);
		} catch (Exception e) {
			log.error(e);
		}
		mainFrame.setVisible(true);
		splashWindow.setVisible(false);
	}

	private static class SplashWindow extends JWindow {

		private static final long serialVersionUID = 1L;

		public SplashWindow() {
			ImageIcon splashIcon = new ImageIcon(
					Util.getResourceURL("splash.png"));
			JLabel label = new JLabel(splashIcon);

			getContentPane().setLayout(null);
			getContentPane().add(label);

			Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
			Dimension sz = new Dimension(splashIcon.getIconWidth(),
					splashIcon.getIconHeight());
			setSize(sz.width, sz.height);
			setLocation((scr.width - sz.width) / 2,
					(scr.height - sz.height) / 2);
			label.setBounds(0, 0, sz.width, sz.height);
		}
	}
}
